/** 
Copyright (c) 2010, Sheikh Abdul Wahid Ahmed
Details @ http://extremecodeworld.codeplex.com/license
**/

using System;
using EXtremecode.Utils;
using System.Data;
namespace EXtremecode.DataAccessLayer
{
	
	public class DADataReader
	{
		private IDataReader m_reader;
        private IDbConnection m_conn;
        private int m_explicitRecordsAffected = -1;
		public DADataReader(IDataReader reader):this(reader,null){}
        public DADataReader(IDataReader reader,IDbConnection conn)
        {
            m_reader = reader;
            m_conn = conn;
        }
		public bool MoveNext()
		{
			if(m_reader==null)return false;
			return m_reader.Read();
		}
        public int RecordsAffected
		{
			get
			{
                if (m_explicitRecordsAffected < 0)
                {
                    if (m_reader == null)
                    {
                        return 0;
                    }
                    else
                    {
                        return m_reader.RecordsAffected;
                    }
                }
                else
                {
                    return m_explicitRecordsAffected;
                }
			}
            internal set
            {
                m_explicitRecordsAffected = value;
            }
		}
		public void Close()
		{
            
            if (m_conn != null)
            {
                try
                {
                    m_conn.Close();
                    m_conn.Dispose();
                }
                catch
                {}
            }

            if (m_reader != null)
            {
                m_reader.Close();
            }
            
		}
		
		public IDataReader ClassicDataReader
		{
			get
			{
				return m_reader;
			}
		}
		public object this[string fieldName]
		{
			get
			{
				if(m_reader==null)return null;
				return m_reader[fieldName];
				
			}
			
		}
		public object this[int columnIndex]
		{
			get
			{
				if(m_reader==null)return null;
				return m_reader[columnIndex];
				
			}
			
		}



	}
}
